<template>
    <t-dialog :header="header" @confirm="onSubmit" :confirmBtn="{
        content: loading?'提交中...':'确认',
        theme: 'primary',
        loading: loading,
      }" :visible.sync="visible" :onClose="closeDialog"     :closeOnOverlayClick="false"
              width="80%" top="5%">
      <div style="height: 65vh">
        <t-table row-key="id"
                 :columns="columns" :data="data" :selected-row-keys="selectedRowKeys"
                 :pagination="pagination" :loading="dataLoading"
                 @select-change="(val)=>{selectedRowKeys=val}">
          <template #applicationField="{row}">
            {{ row.applicationField | filterByDict(dict.type.application_field) }}
          </template>
          <template #innovationCategory="{row}">
            {{ row.innovationCategory | filterByDict(dict.type.innovation_category) }}
          </template>
          <template #op="{row}">
            <t-button @click="dialog.header=row.name;dialog.objId=row.id;dialog.editOpen=false;dialog.open_detail=true" size="small" variant="text" class="t-button-link">
              <t-icon name="info-circle" slot="icon"/>
              推荐详情
            </t-button>
          </template>
        </t-table>
      </div>
      <recommend-detail-dialog :editOpen="dialog.editOpen" :header="dialog.header" :objId="dialog.objId" :visible.sync="dialog.open_detail" v-if="dialog.open_detail"></recommend-detail-dialog>
    </t-dialog>
</template>

<script>
import RecommendDetailDialog from "../../recommend/components/recommend-detail-dialog.vue";


export default {
  name: "select-project",
  dicts: ["application_field", "innovation_category"],
  components:{
    RecommendDetailDialog
  },
  props: {
    header:{
      type:String,
      default:''
    },
    formData: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      dialog:{
        header:"",
        objId:0,
        open_detail: false,
        editOpen: true,
      },
      selectedRowKeys: [],
      sendPorjectInfo:[],
      queryParams: {
        reviewType: '',
        pageNum: 1,
        pageSize: 10,
        dateRange: []
      },
      data:[],
      dataLoading: false,
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0,
        showPageSize: true,
        pageSizeOptions: [10,20,30],
        showFirstAndLastPageBtn: false,
        onChange: (pageInfo) => {
          Object.assign(this.pagination,pageInfo)
          this.queryParams.pageNum = pageInfo.current || 1;
          this.queryParams.pageSize = pageInfo.pageSize;
          this.getList()
        },
      },
      columns: [
        {
          colKey: 'row-select',
          type: 'multiple',
          className: 'demo-multiple-select-cell',
          width: 64,
        },
        {
          colKey: "name",
          title: "成果名称",
          align: "center",
          width: 220
        },
        {
          colKey: "applicationProject",
          title: "应用项目",
          align: "center",
          // ellipsis: true
        },
        {
          colKey: "applicationField",
          title: "应用领域",
          align: "center",
          // ellipsis: true
        },
        {
          colKey: "innovationCategory",
          title: "创新类别",
          align: "center",
          // ellipsis: true
        },
        {
          colKey: "leaderName",
          title: "负责人",
          align: "center",
          // ellipsis: true
        },
        {
          colKey: "deptName",
          title: "工作单位",
          align: "center",
          // ellipsis: true
        },
        {
          colKey: "createTime",
          title: "申报时间",
          align: "center",
          width: 200
        },
        {
          colKey: "op",
          title: "操作",
          align: "center",
          width: 120
        },
      ],
      visible: true,
      loading: false,
    }
  },
  watch: {
    formData: {
      immediate: true,
      handler(val) {
        if(val.id){
          this.getList();
        }
      }
    }
  },
  methods: {
    getList() {
      this.dataLoading = true;
      this.queryParams.innovationCategory = this.formData.innovationCategory;
      this.$api.wcx.review.teamInnovationList(this.queryParams).then((res) => {
        this.data = res.rows;
        this.pagination.total = res.total;
        this.dataLoading = false;
      }).catch((e) => {
        this.dataLoading=false
        this.$message.error(e.toString());
      });
    },

    onSubmit(){
      if(this.selectedRowKeys.length === 0){
        this.$message.error('请选择成果')
        return false
      }
      const businessId = this.selectedRowKeys.map(val=>({
        teamId:this.formData.id,
        businessId:val,
        reviewType: this.formData.reviewType
      }))
      this.loading = true;
      this.$api.wcx.review.teamInnovationsAddList(businessId).then((res) => {
        // 初始化
        this.$message.success("选择成功");
        this.$emit("reload");
        this.$emit("update:visible", false);
        this.loading = false;
      }).catch((e) => {
        this.loading = false;
        this.$message.error(e.toString());
      });
    },
    closeDialog() {
      this.$emit("update:visible", false);
    },

  }
}
</script>

<style scoped>
.overlay-options {
    display: inline-block;
    font-size: 20px;
}
</style>
